function trashmobs_addOptionsPanel (panel)
	panel.name = TRASHMOBS_CAPTION
	InterfaceOptions_AddCategory(panel);
end

--Join new data channel
function trashmobs_OptionsPanelChannelChanged()
	if(trashmobs_settings["CHANNEL_NAME"]~=TrashmobsOptionsFrameChannelName:GetText()) then
		trashmobs_settings["CHANNEL_NAME"]=TrashmobsOptionsFrameChannelName:GetText();
		
		--Clear online user list, groups list
		TRM_ONLINE_USER={};
		trashmobs_UpdateMemberFrame();
		TRM_GROUP_DETAILS={};
		trashmobs_UpdateGroupFrame();
		
		LeaveChannelByName(TRM_DATA_CHANNEL);
		TRM_DATA_CHANNEL = trashmobs_settings["CHANNEL_NAME"];
		trashmobs_JoinDataChannel();
		
	end
end


------------------------------------------------------------------------------
-- set actual character as mainchar 
------------------------------------------------------------------------------
function trashmobs_SetMainChar()

	local guild, guild_rank = GetGuildInfo("player");

	trashmobs_settings["MAINCHAR_NAME"] = UnitName("player");
	trashmobs_settings["MAINCHAR_CLASS"] = UnitClass("player"); 
	trashmobs_settings["MAINCHAR_RACE"] = UnitRace("player");
	trashmobs_settings["MAINCHAR_LEVEL"] = UnitLevel("player");
	trashmobs_settings["MAINCHAR_GUILD"] = guild;
	trashmobs_settings["MAINCHAR_GUILD_RANK"] = guild_rank;

	trashmobs_UpdateState();
	trashmobs_UpdateMemberFrame();
	trashmobs_SendMainCharInfo();
	
end;

------------------------------------------------------------------------------
-- update gui state
------------------------------------------------------------------------------
function trashmobs_UpdateState()

	-- minimap button
	if(trashmobs_settings["SHOW_MINIMAP_BUTTON"]) then
		TrashmobsOptionsFrameMinimapButtonPosSlider:SetValue(
			trashmobs_settings["MINIMAP_BUTTON_POSITION"]);
		TrashmobsOptionsFrameMinimapButtonPosSlider:Show();
		TrashmobsMinimapFrameButton:Show();
	else
		TrashmobsOptionsFrameMinimapButtonPosSlider:Hide();
		TrashmobsMinimapFrameButton:Hide();
	end

	-- mainchar
	if(trashmobs_settings["USE_MAINCHAR_INFO"]) then
		TrashmobsOptionsFrameSetNewMainCharButton:Show();
	else
		TrashmobsOptionsFrameSetNewMainCharButton:Hide();
	end
		
	if(trashmobs_settings["MAINCHAR_NAME"]==UnitName("player")) then
		TrashmobsOptionsFrameSetNewMainCharButton:Disable();
		TrashmobsOptionsFrameSetNewMainCharButton:SetText(UnitName("player"));
	else
		TrashmobsOptionsFrameSetNewMainCharButton:Enable();
		TrashmobsOptionsFrameSetNewMainCharButton:SetText(UnitName("player"));
	end	
	
	-- remember window pos
	if(trashmobs_settings["REMEMBER_WINDOW_POS"]) then
		UIPanelWindows["TrashmobsFrame"] = nil;
	else
		UIPanelWindows["TrashmobsFrame"] = { area="left", pushable=0 };
	end
	
end;

-----------------------------------------------------------------------------
-- load color-menu
-----------------------------------------------------------------------------
function trashmobs_ChannelSetupMenu_OnLoad()
	UIDropDownMenu_Initialize(TrashmobsOptionsFrameChannelSetupMenu,
		trashmobs_ChannelSetupMenu_Initialize, "MENU");
end;

-----------------------------------------------------------------------------
-- initialize and create the color-menu
-----------------------------------------------------------------------------
function trashmobs_ChannelSetupMenu_Initialize()
	
	local item;
	local color;
	local pn = UnitName("player");

	-- chat colors
	item = {};
	item.text = TRASHMOBS_CHANNEL_SETUP_CAPTION;
	item.notCheckable = 1;
	item.isTitle = 1;
	UIDropDownMenu_AddButton(item);

	for k,v in pairs(_channelsetup) do
		local checked = nil;
		local member = "";

		for i,m in ipairs(v["member"],member) do
			if(member~="") then member = member .. ", "; end
			member = member .. m;
		end

		if(v["enabled"]) then checked = 1; end
		item = {};
		item.text = k.."-"..TRASHMOBS_CHANNEL;
		item.value = k;
		item.notCheckable = nil;
		item.notClickable = nil;
		item.hasColorSwatch = 1;
		item.swatchFunc = trashmobs_SetChatTypeColor; 
		item.cancelFunc = FCF_CancelFontColorSettings;
		item.func = trashmobs_ToggleEnableChannel;
		item.keepShownOnClick = 1;
		item.disabled = nil;
		if(member~="") then
			item.tooltipTitle = _printf(TRASHMOBS_CHANNEL_MEMBER, k);
			item.tooltipText = member;
		end
		item.checked = checked;
		if(v["color"]) then
			item.r = v["color"].r;
			item.g = v["color"].g;
			item.b = v["color"].b;
		end
		UIDropDownMenu_AddButton(item);
	end

end;

-----------------------------------------------------------------------------
-- handle click on channelmenu
-----------------------------------------------------------------------------
function trashmobs_ToggleEnableChannel()

	if(_channelsetup[this.value]["enabled"]) then
		-- disable
		_channelsetup[this.value]["enabled"] = false;
		trashmobs_sysmsg(_printf(TRASHMOBS_LEAVE_OTHER, this.value));
		trashmobs_SendChannelLeave(trashmobs_ChannelNameToID(this.value));
		this.checked=_channelsetup[this.value]["enabled"];
	else
		-- enable
		_channelsetup[this.value]["enabled"] = true;
		trashmobs_sysmsg(_printf(TRASHMOBS_JOIN_OTHER,this.value));
		trashmobs_SendChannelJoin(trashmobs_ChannelNameToID(this.value));
		this.checked=_channelsetup[this.value]["enabled"];
	end
end;